package game.targets.entity;

import game.targets.Locator;
import game.targets.observer.Subject;

import com.badlogic.gdx.math.Quaternion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.bullet.dynamics.btRigidBody;

public abstract class CollisionEntity extends Entity {
    protected PhysicsComponent physics;
    protected Quaternion quat;
    protected boolean matchModelRotation;

    public CollisionEntity(Vector3 pos, Vector3 rotation, Vector3 graphicRotation, float mass, Vector3 vertices, boolean isStatic, boolean isCylinder, String path,
            Subject subject) {
        super(pos, rotation, graphicRotation, path, subject);
        physics = new PhysicsComponent(pos, rotation, mass, this, vertices, 1, isStatic, isCylinder);
        quat = new Quaternion();
        matchModelRotation=true;
    }

    public CollisionEntity(Vector3 pos, Vector3 vertices, boolean isStatic, boolean isCylinder, String path, Subject subject) {
        this(pos, new Vector3(0, 0, 0), new Vector3(0, 0, 0), 1, new Vector3(0, 0, 0), isStatic, isCylinder, path, subject);
    }
    
    

    @Override
    public void update(float delta) {
        position = physics.getBody().getWorldTransform().getTranslation(position);
        if (graphics.getInstance() != null && matchModelRotation) {
           /* physics.getBody().getWorldTransform().getRotation(quat);
            Vector3 tmp=new Vector3();
            float angle=quat.getAxisAngle(tmp);
            graphics.getInstance().transform.setToRotation(tmp,angle);
            graphics.getInstance().transform.scale(scale,scale,scale);*/
        }
        if(physics.getBody().getCenterOfMassPosition().y < -100){
        	exists=false;
        }
    }
    
    public void setPhysicsScale(float scale){
        physics.setScale(scale);
    }

    @Override
    public void prepForDeletion() {
        Locator.getWorld().removeRigidBody(physics.getBody());
        physics.dispose();
    }

    public btRigidBody getBody() {
        return physics.getBody();
    }

    public abstract void onCollide(CollisionEntity a);

}
